<template>
	<view>
		<!-- 自定义导航栏 -->
		<z-nav-bar transparentFixedFontColor="#FFF" :scrollTop="scrollTop" type="transparentFixed" title="礼物记录"></z-nav-bar>
		<!-- 公共组件-每个页面必须引入 -->
		<public-module></public-module>
		<view class="h-bg" :style="'background-image: url('+headBgImg+');'">
			<view class="box flex align-item j-between">
				<view class="box-item flex column align-item">
					<view class="t1">
						{{ total_price || 0.00 }}
					</view>
					<view class="t2">
						礼币数
					</view>
				</view>
				<view class="box-item flex column align-item">
					<view class="t1">
						{{ total_num || 0 }}
					</view>
					<view class="t2">
						礼物数
					</view>
				</view>
			</view>
		</view>
		<view class="main">
			<!-- 切换栏 -->
			<view class="qiehuan flex align-item">
				<view class="qiehuan-item flex align-item column">
					<view class="qiehuan-item-tit-com" :class="type == 0 ? 'qiehuan-item-tit-on' : 'qiehuan-item-tit'" @click="change(0)">
						收到礼物
					</view>
					<view class="qiehuan-item-icon" v-if="type == 0"></view>
				</view>
				<view class="qiehuan-item flex align-item column">
					<view class="qiehuan-item-tit-com" :class="type == 1 ? 'qiehuan-item-tit-on' : 'qiehuan-item-tit'" @click="change(1)">
						赠送礼物
					</view>
					<view class="qiehuan-item-icon" v-if="type == 1"></view>
				</view>
			</view>
			<!-- 内容 -->
			<view class="" v-if="giveGiftData.length > 0">
				<view class="flex align-item j-between content" v-for="(item,index) in giveGiftData" :key="index">
					<view class="flex content-left">
						<view class="content-left-img">
							<image :src="item.gift_image" mode=""></image>
						</view>
						<view class="content-left-info">
							<view class="content-left-info-name">
								{{ item.name }}
							</view>
							<view class="content-left-info-t" v-if="type == 0">
								<text class="content-left-info-t-1" style="margin-right: 20rpx;">{{ item.type == 1 ? item.give_nickname : '' }}</text>
								<text class="content-left-info-t-2">{{ item.type == 1 ? '赠送' : '' }}</text>
								<text class="content-left-info-t-3">x{{ item.num }}</text>
							</view>
							<view class="content-left-info-t" v-else>
								<text class="content-left-info-t-2">赠送</text>
								<text class="content-left-info-t-1" style="margin-right: 20rpx;">{{ item.user_name }}</text>
								<text class="content-left-info-t-3">x{{ item.num }}</text>
							</view>
							<view class="content-left-info-time">
								{{ item.createtime }}
							</view>
						</view>
					</view>
					<view class="content-right flex column align-item j-between">
						<!-- <view class="content-right-price">
							{{ item.price }}
						</view> -->
					</view>
				</view>
			</view>
			<view class="" style="margin-top: 200rpx;" v-else>
				<u-empty
				        mode="data"
				        icon="http://cdn.uviewui.com/uview/empty/data.png"
						text=" "
				>
				</u-empty>
			</view>
			
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				imgUrl: this.$http.baseUrl, // 服务器域名
				headBgImg: this.$http.baseUrl + 'static/web/img/gift_bg.png', //顶部背景图片 
				type: 0, // 切换栏
				giveGiftData: [], // 存储我的礼物信息
				limit: 10, // 每页的请求条件
				page: 1, // 页码
				total: 0, // 数据总数量
				total_price: '', // 礼币数
				total_num: '', // 礼物数
				scrollTop: 0, // 顶部导航栏类型
			}
		},
		methods: {
			// 切换tab栏
			change(i){
				this.type = i
				this.giveGiftData = []
				this.page = 1
				this.getGiveGift()
			},
			// 获取我的礼物和我赠送的礼物
			getGiveGift(){
				var that = this
				this.$http.get('api/ZhGiveGift/index',{'type':that.type,'page':that.page,'limit':that.limit}).then(res=>{
					if(res){
						that.giveGiftData = [...that.giveGiftData,...res.list]
						that.total = res.count
						that.total_price = res.total_price
						that.total_num = res.total_num
					}
				})
			}
		},
		onLoad() {
			this.getGiveGift()
		},
		// 监听滑动事件
		onPageScroll(e) {
			this.scrollTop = e.scrollTop
		},
		// 触底触发
		onReachBottom() {
			if(this.giveGiftData.length < this.total){
				this.page++
				this.getGiveGift()
			}
		},
	}
</script>

<style lang="scss">
.flex {
	display: flex;
}
.align-item {
	align-items: center;
}
.j-between {
	justify-content: space-between;
}
.column {
	flex-direction: column;
}
.h-bg {
	position: relative;
	top: 0;
	width: 100%;
	padding: 225rpx 0 116rpx;
	background-size: 100% 100%;
	image {
		width: 100%;
	}
	.box {
		width: 100%;
		.box-item {
			width: 50%;
			.t1 {
				font-size: 60rpx;
				font-family: WeChat-Sans-Std-Medium, WeChat-Sans-Std;
				font-weight: 500;
				color: #FFFFFF;
				line-height: 66rpx;
				margin-bottom: 15rpx;
			}
			.t2 {
				font-size: 26rpx;
				font-family: PingFangSC-Light, PingFang SC;
				font-weight: 300;
				color: rgba($color: #fff, $alpha: .7);
				line-height: 37rpx;
			}
		}
	}
}
.main {
	padding: 63rpx 30rpx 60rpx;
	.qiehuan {
		.qiehuan-item {
			margin-right: 64rpx;
			.qiehuan-item-tit-com {
				display: flex;
				align-items: flex-end;
				font-family: PingFangSC-Light, PingFang SC;
				height: 56rpx;
				margin-bottom: 20rpx;
				vertical-align: baseline;
			}
			.qiehuan-item-tit {
				font-size: 28rpx;
				font-weight: 300;
				color: #6A6A7E;
			}
			.qiehuan-item-tit-on {
				font-size: 40rpx;
				font-weight: 500;
				color: #000013;
			}
			.qiehuan-item-icon {
				width: 20rpx;
				height: 10rpx;
				background: #7F5AFF;
				border-radius: 10rpx 10rpx 0 0;
			}
		}
	}
	.content {
		margin-top: 54rpx;
		.content-left {
			.content-left-img {
				width: 148rpx;
				height: 148rpx;
				margin-right: 25rpx;
				image {
					width: 100%;
					height: 100%;
				}
			}
			.content-left-info {
				.content-left-info-name {
					font-size: 32rpx;
					font-family: PingFangSC-Regular, PingFang SC;
					font-weight: 500;
					color: #000013;
				}
				.content-left-info-t {
					font-family: PingFangSC-Light, PingFang SC;
					font-weight: 500;
					color: #000013;
					margin-top: 24rpx;
					.content-left-info-t-1 {
						font-size: 24rpx;
					}
					.content-left-info-t-2 {
						font-size: 24rpx;
						// color: #BEC6D3;
						margin-right: 24rpx;
					}
					.content-left-info-t-3 {
						font-size: 28rpx;
					}
				}
				.content-left-info-time {
					font-size: 24rpx;
					font-family: PingFangSC-Light, PingFang SC;
					font-weight: 300;
					color: #BEC6D3;
					margin-top: 6rpx;
				}
			}
		}
		.content-right {
			height: 148rpx;
			.content-right-price {
				font-size: 36rpx;
				font-family: WeChat-Sans-Std-Medium, WeChat-Sans-Std;
				font-weight: 500;
				color: #7F5AFF;
			}
			.content-right-btn {
				width: 128rpx;
				height: 56rpx;
				background: #FFFFFF;
				border-radius: 28rpx;
				border: 1rpx solid #7F5AFF;
				line-height: 56rpx;
				text-align: center;
				font-size: 28rpx;
				font-family: PingFangSC-Regular, PingFang SC;
				font-weight: 400;
				color: #7F5AFF;
			}
		}
	}
}

</style>
